#include <stdio.h>

void shellsort(char a[],int n)
{
	int j,i,m,mid;
	for(m = n/2;m>0;m/=2)
	{
		for(j = m;j< n;j++)
		{
			for(i=j-m;i>=0;i-=m)
			{
				if(a[i+m]>=a[i])
					break;
				else
				{
					mid = a[i];
					a[i] = a[i+m];
					a[i+m] = mid;
				}
			}
		}
	}
}

int main()
{
	char str1[]= "abc", str2[] = "bda";

	int i;

	for (i=0; str1[i] && str2[i]; i++);
	
	if (str1[i] != str2[i])
	{
		printf ("Not anagrams. [%s] and [%s] are of different lengths", str1, str2);
		return -1;
	}

	shellsort(str2, i);
	shellsort(str1, i);

	printf ("\n%s\t%s\n", str1, str2);

	for (i=0; str1[i] && str1[i] == str2[i]; i++);

	if (str1[i])
		printf ("not anagrams");
	else
		printf ("anagrams");

	return 0;
}
